package com.sip.stream.base

import android.os.Bundle
import android.view.LayoutInflater
import androidx.viewbinding.ViewBinding
import me.yokeyword.fragmentation.SupportActivity
import java.lang.reflect.ParameterizedType


abstract class BaseActivityBundle<VB : ViewBinding> : SupportActivity() {

    lateinit var binding: VB


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = getViewBindingForActivity(layoutInflater)
        setContentView(binding.root)
        initPage(savedInstanceState)
    }

    abstract fun initPage(savedInstanceState: Bundle?)

    @Suppress("UNCHECKED_CAST")
    private fun getViewBindingForActivity(layoutInflater: LayoutInflater): VB {
        val type = javaClass.genericSuperclass as ParameterizedType
        val aClass = type.actualTypeArguments[0] as Class<*>
        val method = aClass.getDeclaredMethod("inflate", LayoutInflater::class.java)
        return method.invoke(null, layoutInflater) as VB
    }

    override fun finish() {
        super.finish()
        overridePendingTransition(0, 0)
    }

    override fun onPause() {
        super.onPause()
        overridePendingTransition(0, 0)
    }
}